import 'package:flutter/material.dart';

import '../page/home/homePage.dart';
import '../page/message/messagePage.dart';
import '../page/mine/minePage.dart';

class Home extends StatefulWidget {
  const Home({Key? key}) : super(key: key);

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  //菜单
  final List<BottomNavigationBarItem> bottomNav = [
    BottomNavigationBarItem(
      backgroundColor: Colors.blueAccent,
      icon: Icon(Icons.home),
      label: '首页',
    ),
    BottomNavigationBarItem(
      backgroundColor: Colors.blueAccent,
      icon: Icon(Icons.message),
      label: '消息',
    ),
    BottomNavigationBarItem(
      backgroundColor: Colors.blueAccent,
      icon: Icon(Icons.person),
      label: '我的',
    ),
  ];
  //页面
  final Pages = [
    HomePage(),
    MessagePage(),
    MinePage(),
  ];
  late int currentIndex;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    currentIndex = 0;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: BottomNavigationBar(items: bottomNav,
        currentIndex: currentIndex,
        selectedItemColor: Colors.blueAccent,
        type: BottomNavigationBarType.fixed,
        onTap: (index){
          _changePage(index);
        },

      ),
      body: Pages[currentIndex],

    );
  }
  void _changePage(int index){
    if(index != currentIndex){
      setState(() {
        currentIndex = index;
      });

    }

  }
}
